﻿@{
    ViewBag.Title = "模具档案管理";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<link href="~/Content/css/BlankingcardManagement_print.css" rel="stylesheet" media="print" />
<style type="text/css">
    #print {
        display: none;
    }

    .tool_c {
        padding: 10px 0;
    }

    .btn-group {
        padding: 0 10px 0 0;
    }

    .grid_list_2_c {
        overflow: hidden;
    }

        .grid_list_2_c .frozen-bdiv {
            top: 34px !important;
        }

        .grid_list_2_c .frozen-div {
            height: 3em !important;
        }

        .grid_list_2_c .ui-jqgrid-hdiv {
            width: 1900px !important;
            background-color: transparent !important;
        }

        .grid_list_2_c .ui-jqgrid-bdiv {
            width: 1900px !important;
            background-color: transparent !important;
        }

        .grid_list_2_c .ui-jqgrid-btable {
            background-color: #fff !important;
        }

    .btn-group:last-child a.btn:first-child {
        margin: 0 0.5em 0 0 !important;
    }

    .input_inline input {
        display: inline-block;
        width: 4em;
    }

    #gridList1 td:nth-child(3) a:visited, #gridList1 td:nth-child(3) a:link {
        text-decoration: underline;
    }

    #gridList1 td:nth-child(3) a:hover {
        text-decoration: underline;
        color: #c00;
    }

    #gridList1 td:nth-child(3) a[disabled] {
        color: #ccc;
        text-decoration: line-through;
    }

    .grid_list_1_c a[disabled] {
        pointer-events: none;
        cursor: not-allowed;
        filter: alpha(opacity=65);
        -webkit-box-shadow: none;
        box-shadow: none;
        opacity: .65;
    }

    .btn-group input {
        height: 2em !important;
    }
</style>
<script>
    $(function () {
        Index.init();
    });

    var Index = {
        useUnit: '@Html.Raw(ViewData["useUnit"].ToString())',
        dataList: null,
        selected: [],
        page: 1,
        curSelected: -1,
        init: function () {
            with (Index) {
                initControl();

                loadDataList();
            }
        },
        initControl: function () {
            !!$.request("page") && (Index.page = $.request("page"));

            $("#gridList1").delegate("[type=checkbox]", "click", function () {
                var cur = $(this);

                var foo = cur.is(":checked");

                foo && (function () {
                    var val = $.grep(Index.selected, function (n, i) {
                        return n.id == cur.val();
                    });

                    !val[0] && Index.selected.push({ id: cur.val(), status: cur.attr("status") });
                })();

                foo || (function () {
                    var val = $.grep(Index.selected, function (n, i) {
                        return n.id == cur.val();
                    });

                    !!val[0] && Index.selected.splice(Index.selected.indexOf(val[0]), 1);
                })();

            });
            $('select').bindSelect();
            //生产单位数据
            $("#MoldUnit").bindSelect({
                url: "/BaseData/ZSJ_B1_GH_SI/GetProduceUnit",
                id: "MakeLineNO",
                text: "MakeLineNOName"
            });
            $("#MoldWorkshop").bindSelect({
                url: "/BaseData/ZSJ_B1_GH_SI/GetProduceUnit",
                id: "MakeLineNO",
                text: "MakeLineNOName"
            });
            //制造单位数据
            $(".FProCompanyName").bindSelect({
                url: "/BaseData/ZSJ_B1_GH_SI/GetGridJson?isProduct=1",
                id: "UnitNO",
                text: "UnitNOShortName"
            });
            //批次查询 btn_search1
            $("#btn_search1").on("click", function () {
                var $gridList1 = $("#gridList1");

                var conn1 = $.buildPostParam("MoldNO,MoldName,AssetsNO,MoldUnit,MoldWorkshop,WorkpieceNo,ManuUnit");

                $gridList1.jqGrid('setGridParam', {
                    postData: conn1,
                }).trigger('reloadGrid');
            });

            $("#butnGoAdd").on("click", function () {
                var url = "/Mould/MouldArchive/MouldArchiveAdd";

                location.href = url;

                //$.modalOpen({
                //    url: url,
                //    width: "1280px",
                //    height: "700px",
                //    close: true
                //});
            });

            $("#gridList1").delegate("[编辑]", "click", function () {
                var jsonData = { id: $(this).attr("编辑") };

                jsonData["page"] = $("#gridList1").jqGrid("getGridParam", "page");

                jsonData["idx"] = $(this).parents("tr").attr("id");

                var url = "/Mould/MouldArchive/MouldArchiveAdd?{0}".format($.param(jsonData));

                location.href = url;

                //$.modalOpen({
                //    url: url,
                //    width: "1280px",
                //    height: "700px",
                //    close: true
                //});
            });

            $("#gridList1").delegate("[删除]", "click", function () {
                var jsonData = { id: $(this).attr("删除") };
                //当disabled属性存在时不执行删除。
                !!$(this).attr("disabled") || (function () {
                    $.modalConfirm("是否确定删除此条记录？", function (foo) {
                        foo && (function () {
                            $.post("/Mould/MouldArchive/DeleteMouldArchive", jsonData, function (res) {
                                0 < res && (function () {
                                    $.modalAlert("删除成功！", "success");

                                    $("#btn_search1").trigger("click");
                                })();
                            });
                        })();
                    }, true);
                })();
            });

            $("#butnPublish").on("click", function () {
                !!Index.selected.length || $.modalAlert("请选择需要发布的记录。", "error");
                
                !!Index.selected.length && (function () {
                    var ids = [], jsonData = { type: 1, ids: "" };

                    for (var idx in Index.selected) {
                        "2" != Index.selected[idx].status && ids.push(Index.selected[idx].id);
                    }

                    jsonData.ids = ids.join(",");

                    $.post("/Mould/MouldArchive/ChangeMouldArchive", jsonData, function (res) {
                        0 < res && (function () {
                            $.modalAlert("发布成功！", "success");

                            $("#btn_search1").trigger("click");
                        })();
                    });
                })();
            });

            $("#butnForzen").on("click", function () {
                !!Index.selected.length || $.modalAlert("请选择需要冻结的记录。", "error");

                !!Index.selected.length && (function () {
                    var ids = [], jsonData = { type: 2, ids: "" };

                    for (var idx in Index.selected) {
                        "1" != Index.selected[idx].status && ids.push(Index.selected[idx].id);
                    }

                    jsonData.ids = ids.join(",");

                    $.post("/Mould/MouldArchive/ChangeMouldArchive", jsonData, function (res) {
                        0 < res && (function () {
                            $.modalAlert("冻结成功！", "success");

                            $("#btn_search1").trigger("click");
                        })();
                    });
                })();
            });

            $("#butnExport").on("click", function () {
                var param = { id: "V_Mol_11_DA_Mold", param: Index.buildExportConn("MoldNO,MoldName,AssetsNO,MoldUnit,MoldWorkshop,WorkpieceNo,ManuUnit".split(",")) };

                var url = "/Common/ExcelExportById?{0}".format($.param(param));

                location.href = url;
            });
        },
        buildExportConn: function (params) {
            var conn = "";

            params.forEach(function (item) {
                var val = $("#{0}".format(item)).val();
                !!val && (conn += ("and {0} = '{1}'".format(item,val)));
            });

            return conn;
        },
        loadDataList: function () {
            var conn1 = $.buildPostParam("MoldNO,MoldName,AssetsNO,MoldUnit,MoldWorkshop,WorkpieceNo,ManuUnit");

            var customFmatter = function (cellvalue, options, rowObject) {
                return "{0}%".format(cellvalue * 100);
            };

            var onSelectedFormat = function (cellvalue, options, rowObject) {
                var vals = cellvalue.split(',');

                return "<input type=\"checkbox\" status=\"{1}\" value=\"{0}\"/>".format(vals[1], vals[0]);
            };

            var onEditFormat = function (cellvalue, options, rowObject) {

                var vals = cellvalue.split(',');

                var obj = { id: vals[1], status: (0 == vals[0] ? "" : "disabled") };

                var template = "<a href=\"javascript:void(0);\"  编辑=\"{id}\">编辑</a>&nbsp;<a  href=\"javascript:void(0);\"  删除=\"{id}\" {status}>删除</a>";

                return template.format(obj);
            };

            var $gridList1 = $("#gridList1");///BOM/Blankingcard/GetBlankingcards
            $gridList1.dataGridForJson({
                url: "/Mould/MouldArchive/GetMouldArchivies",
                postData: conn1,
                height: $(window).height() - 220,
                page: Index.page,
                colModel: [
                { label: '选择', name: 'mstatusid', width: 40, align: 'center', sortable: false, frozen: true, formatter: onSelectedFormat, frozen: true },
                { label: '操作', name: 'mstatusid', width: 80, align: 'center', sortable: false, frozen: true, formatter: onEditFormat, frozen: true },
                { label: '维护<br/>状态', name: 'MaintainStatusName', width: 40, align: 'center', sortable: false, frozen: true },
                { label: 'ID(隐藏)', name: '	Moldid', width: 160, align: 'left', sortable: false, frozen: true, hidden: true },
                { label: '建档日期', name: 'RegistrationDate', width: 80, align: 'center', sortable: false, frozen: true },
                { label: '制件编号', name: 'WorkpieceNo', width: 120, align: 'left', sortable: false, frozen: true },
                { label: '制件名称', name: 'WorkpieceName', width: 160, align: 'left', sortable: false, frozen: true },
                { label: '工序编号', name: 'ProcessNO', width: 120, align: 'left', sortable: false, frozen: true },
                { label: '模具编号', name: 'MoldNO', width: 280, align: 'left'},
                { label: '模具名称', name: 'MoldName', width: 160, align: 'left', sortable: false },
                { label: '资产编号', name: 'AssetsNO', width: 120, align: 'left', sortable: false },
                { label: '模具数量', name: 'MoldNum', width: 80, align: 'right', sortable: false },
                { label: '模具寿命<br/>（冲次）', name: 'MoldLife', width: 80, align: 'right', sortable: false },
                { label: '模具尺寸', name: 'MoldSize', width: 140, align: 'left', sortable: false },
               { label: '	闭合高度', name: 'CloseHeight', width: 80, align: 'right', sortable: false },
                { label: '模具重量<br/>（吨）', name: 'MoldWeight', width: 80, align: 'right', sortable: false, formatter: 'number' },
                { label: '上模重量<br/>（吨）', name: 'TopWeight', width: 80, align: 'right', sortable: false, formatter: 'number' },
                { label: ' 复制模具', name: 'CopyMold', width: 80, align: 'right', sortable: false },
                { label: '共用产品', name: 'MoldProductionNO', width: 80, align: 'right', sortable: false },
                { label: '模具类别（隐藏）	', name: 'MoldCategory', width: 160, align: 'left', sortable: false, hidden: true },
                { label: '模具类别', name: 'MoldCategoryName', width: 80, align: 'center', sortable: false },
                { label: ' 模具产品类型（隐藏）', name: 'MoldType', width: 80, align: 'right', sortable: false, hidden: true },
                { label: '模具产品类型', name: 'MoldTypeName', width: 80, align: 'center', sortable: false },
                { label: '转固时间<br/>（年）', name: 'TransDate', width: 80, align: 'right', sortable: false },
                { label: '转固原值<br/>（万元）', name: 'TransValues', width: 80, align: 'right', sortable: false },
                { label: '产权单位（隐藏）', name: 'RightUnit', width: 80, align: 'right', sortable: false, hidden: true },
                { label: '产权单位', name: 'RightUnitName', width: 160, align: 'left', sortable: false },
                { label: '投入使用日期', name: 'PutDate', width: 100, align: 'center', sortable: false },
                { label: '已使用冲次', name: 'UsedPress', width: 80, align: 'right', sortable: false },
                { label: '使用<br/>状态', name: 'IsDisable', width: 40, align: 'right', sortable: false },
                { label: '制造单位', name: 'ManuUnit', width: 120, align: 'left', sortable: false },
                { label: '制造单位名称', name: 'ManuUnitName', width: 160, align: 'left', sortable: false },
                 { label: '使用单位', name: 'MoldUnit', width: 120, align: 'left', sortable: false },
                { label: '使用单位名称', name: 'MoldUnitName', width: 160, align: 'left', sortable: false },
                { label: '使用车间', name: 'MoldWorkshop', width: 120, align: 'left', sortable: false },
                { label: '使用车间名称', name: 'MoldWorkshopName', width: 200, align: 'left', sortable: false },
                { label: '产品车型分布', name: 'VehicleDistr', width: 120, align: 'left', sortable: false },
                { label: '保养周期<br/>（次）', name: 'MaintenCycle', width: 80, align: 'right', sortable: false },
                { label: '维修周期<br/>（次）', name: 'RinseCycle', width: 80, align: 'right', sortable: false },
                { label: '项目单位', name: 'ProjectUnit', width: 80, align: 'left', sortable: false },
                { label: '项目单位名称', name: 'ProjectUnitName', width: 160, align: 'left', sortable: false },
                { label: '项目编号', name: 'ProjectNo', width: 120, align: 'left', sortable: false },
                { label: '备注说明', name: 'MoldExplain', width: 160, align: 'left', sortable: false },
                { label: '创建人员', name: 'InputUser', width: 80, align: 'center', sortable: false },
                { label: '创建日期', name: 'InputDate', width: 80, align: 'center', sortable: false },
                { label: '创建时间', name: 'InputTime', width: 80, align: 'center', sortable: false },
                 { label: '发布人员', name: 'FAuditingBy', width: 80, align: 'center', sortable: false },
                 { label: '发布日期', name: 'FAuditingDate', width: 80, align: 'center', sortable: false },
                 { label: '发布时间', name: 'FAuditingTime', width: 80, align: 'center', sortable: false }
                ],
                pager: "#gridPager1",
                sortname: 'UseUnit,MoldNO',
                sortorder: "asc ",
                viewrecords: true,
                rownumWidth: 50,
                onSelectRow: function (rowId) {

                },
                loadComplete: function (data) {
                    Index.dataList = data;

                    Index.selected = [];

                    !!$.request("idx") && (Index.curSelected = $.request("idx"));

                    -1 != Index.curSelected && $("#gridList1").jqGrid('setSelection', Index.curSelected);
                }
            });

            $gridList1.jqGrid('setFrozenColumns');
        }
    };



</script>
<div class="layout" id="layout" style="height: 100%; width: 100%;">
    <div class="tool_c">
        <div class="btn-group input-width-185">
            &nbsp;模具编号<br />
            <input id="MoldNO" name="" placeholder="" type="text" class="form-control required" />
        </div>
        <div class="btn-group input-width-185">
            &nbsp;模具名称<br />
            <input id="MoldName" name="" placeholder="" type="text" class="form-control required" />
        </div>
        <div class="btn-group input-width-185">
            &nbsp;资产编号<br />
            <input id="AssetsNO" name="" placeholder="" type="text" class="form-control required" />
        </div>
        <div class="btn-group input-width-185">
            &nbsp;使用单位<br />
            <select id="MoldUnit" class="sel_common ProductUnit">
                <option value="">请选择</option>
            </select>
        </div>
        <div class="btn-group input-width-185">
            &nbsp;使用车间<br />
            <select id="MoldWorkshop" class="sel_common ProductUnit">
                <option value="">请选择</option>
            </select>
        </div>
        <div class="btn-group input-width-185">
            &nbsp;制件编号<br />
            <input id="WorkpieceNo" name="" placeholder="" type="text" class="form-control required" />
        </div>
        <div class="btn-group input-width-185">
            &nbsp;制造单位<br />
            <select id="ManuUnit" class="sel_common FProCompanyName">
                <option value="">请选择</option>
            </select>
        </div>
        <div class="btn-group">
            <a id="btn_search1" class="btn btn-primary center-block"><span class="glyphicon glyphicon-search"></span>查询</a>
            <a class="btn btn-primary center-block" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span>刷新</a>
            <a id="butnGoAdd" class="btn btn-primary center-block"><span class="glyphicon glyphicon-plus"></span>新增</a>
            <a id="butnPublish" class="btn btn-primary center-block i1 i12"><span class="glyphicon glyphicon-flag"></span>发布</a>
            <a id="butnForzen" class="btn btn-primary center-block"><span class="glyphicon glyphicon-lock"></span>冻结</a>
            <a id="butnExport" class="btn btn-primary center-block"><span class="glyphicon glyphicon-export"></span>导出</a>
        </div>
    </div>
    <div class="grid_list_1_c" style="margin-top: 5px;">
        <table id="gridList1"></table>
        <div id="gridPager1"></div>
    </div>
    <div id="print">
    </div>
</div>



 